﻿export function init(containerId, options) {
    const viewers = window.OPEN_SEADRAGON_VIEWERS = {};
    viewers[containerId] = OpenSeadragon({
        id: containerId,
        prefixUrl: "/openseadragon/images/",
        tileSources: {
            type: 'image'
        },
        ...options
    });
}

export function open(containerId, imageUrl) {
    const viewers = window.OPEN_SEADRAGON_VIEWERS;
    if (viewers && viewers[containerId]) {
        if (viewers[containerId].viewport) {
            viewers[containerId].viewport.setRotation(0);
        }
        viewers[containerId].open({
            type: 'image',
            url: imageUrl
        });
    }
}

export function dispose(containerId) {
    const viewers = window.OPEN_SEADRAGON_VIEWERS;
    if (viewers && viewers[containerId]) {
        viewers[containerId].destroy();
    }
}